/*eslint-disable*/
import React, { useState, useEffect } from 'react'
import { Table, Space, Button, Cascader, Modal, Input,message, Switch } from 'antd';
import request from '../../../utils/request'
import Linkage from '../../../components/linkage'
const group = () => {
    const options1 = [
        {
            value: '开启',
            label: '开启',
        },
        {
            value: '关闭',
            label: '关闭',
        }
    ];
    function onChange(value) {
        console.log(value);
    }
    const columns = [
        {
            title: '序号',
            dataIndex: 'id',
            key: 'id',
        },
        {
            title: '图片',
            dataIndex: 'img',
            key: 'img',
        },
        {
            title: '楼盘名称',
            dataIndex: 'name',
            key: 'name',
        },
        {
            title: '楼盘地址',
            dataIndex: 'dizhi',
            key: 'dizhi',
        },
        {
            title: '发起人',
            dataIndex: 'faqi',
            key: 'faqi',
        },
        {
            title: '起始时间',
            dataIndex: 'datimer',
            key: 'datimer',
        },
        {
            title: '团购状态',
            dataIndex: 'tuangou',
            key: 'tuangou',
        },
        {
            title: '状态',
            dataIndex: 'zhuangtai',
            key: 'zhuangtai',
            render:(o,record,index)=>{
                return(
                    <Switch defaultChecked={record.status==="1" ? true:false } checkedChildren="开启" unCheckedChildren="关闭"/>
                )
            }
        },
        {
            title: '操作',
            key: 'action',
            render: (text,record) => (
                <Space size="middle">
                    <a onClick={() => del(record.id)}>删除</a>
                </Space>
            ),
        },
    ];
    const [list, setlist] = useState([])

    //添加弹框
    const addModal = () => {
        setFlag(false)
        setIsModalVisible(true);
    };
    //取消键
    const handleCancel = () => {
        setIsModalVisible(false);
    };

    useEffect(() => {
        tablelist()
    }, [])

    const tablelist = async () => {
        const res = await request.get('/api/list3')
        setlist([...res.data.data])
    }

    //删除
    const del =async (id) => {
        const res=await request.delete('/api/list3del',{id:id})
        console.log(res);
        tablelist()
    }
    //搜索
    const onSearch = (value) => {
        console.log(value)
        request.post('/api/list6search', { value: value }).then(res => {
            console.log(res);
            tablelist()
        })
    };
    return (
        <div>
            <header>
                团购管理
            </header>
            <div className="div-btn">
                <div className="inp">搜索<span><input placeholder="请输入经纪人姓名/手机号" onChange={(e) => onSearch(e.target.value)}/></span></div>
                <div>状态<span><Cascader options={options1} onChange={onChange} placeholder="请选择" /></span></div>
                <div className="inp"><span><input placeholder="关键字" onChange={(e) => onSearch(e.target.value)}/></span></div>
                <div><span><Cascader options={options1} onChange={onChange} placeholder="请选择状态" /></span></div>
                <div><Button >查询</Button></div>
            </div>
            <Linkage/>
            <div>
                <Table columns={columns} dataSource={list} />
            </div>
        </div>
    )
}
export default group
